<script type="text/javascript">
$(function(){
	var pg = App.base.sysParamEdit.ui;
	var frm = {
		catalog: pg.seek('catalog'), // 分组
		code: pg.seek('envCode'), // 参数名
		value: pg.seek('value'), // 值
		status: pg.seek('status'), // 0未启用，1启用
		memo: pg.seek('memo') // 备注
	};
	frm.status.mac('combo', {
		width: 340,
		boxWidth: 340,
		data: Cache.base.user.status
	});
	function getValues(){
		return {
			code: frm.code.val(),
			catalog: frm.catalog.val(),
			value: frm.value.val(),
			status: frm.status.val(),
			memo: frm.memo.val(),
			id: pg.params.id,
		};
	}
	function setValues(o){
		pg.children('.title').html(o.id? '编辑参数信息':'添加参数');
		frm.code.val(o.code);
		frm.catalog.val(o.catalog);
		frm.value.val(o.value);
		frm.status.val([o.status]);
		frm.memo.val(o.memo);
	}
	function validate(p){
		var m = pg.seek('msg').html(''), v = App.base.validation, x = App.validate;
		return x(v.env.code, p.code, m, '参数名')&&
			x(v.env.catalog, p.catalog, m, '分组')&&
			x(v.env.value, p.value, m, '值')&&
			x(v.env.status, p.status, m, '状态')&&
			x(v.env.memo, p.memo, m, '备注')
		;
	}
	pg.find('input').blur(function(){
		var pms = getValues();
		if (!validate(pms))
			return;
	});
	pg.seek('ok').click(function(){
		var pms = getValues();
		if (!validate(pms))
			return;
		$.post(App.ctx + '/param/save.do', pms, function(rs){
			var ro = mac.eval(rs);
			if (ro.success) {
				pg.close();
				pg.callback();
			} else {
				pg.seek('msg').html(mac.msg(ro.data, ro.params));
			}
		});
		return false;
	});
	setValues(pg.params || {});
});
</script>
<div class="form">
	<h3 class="title hidden">参数配置</h3>
	<div class="item">
		<span class="label">分组：</span> 
		<input type="text" name="catalog" />
		<span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<div class="label">参数名：</div>
		<input type="text" name="envCode" pattern="\w+(\.\w+)*"/>
		<span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">值：</span> 
		<input type="text" name="value" /> 
		<span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">状态：</span>
		<div class="combo fl" name="status"></div>
		<span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">备注：</span>
		<textarea name="memo"></textarea>
		<span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">&nbsp;</span>
		<div name="msg" class="msg"></div>
		<div class="clear"></div>
	</div>
	<div class="bottom">
		<button name="ok">保存</button>
	</div>
</div>
